package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.SaleList;
import com.atguigu.jxc.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/saleListGoods")
public class SaleController {
    @Autowired
    private SaleService saleService;

    //进货单保存
    @PostMapping("/save")
    public ServiceVO save(SaleList saleList, String saleListGoodsStr) {
        this.saleService.saveSaleList(saleList, saleListGoodsStr);
        return new ServiceVO(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
    }

    //进货单列表展示
    @PostMapping("/list")
    public Map<String, Object> list(String saleNumber, Integer customerId, Integer state, String sTime, String eTime) {
        return saleService.getSaleList(saleNumber, customerId, state, sTime, eTime);
    }

    //    http://localhost:8080/SaleListGoods/goodsList
    @PostMapping("/goodsList")
    public Map<Object, Object> goodsList(Integer saleListId) {
        return saleService.getSaleListGoods(saleListId);
    }

    //进货单删除
    @PostMapping("/delete")
    public ServiceVO delete(Integer SaleListId) {
        this.saleService.SaleDelete(SaleListId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
    }

    //支付结算（修改进货单付款状态）http://localhost:8080/SaleListGoods/updateState
    @PostMapping("/updateState")
    public ServiceVO updateState(Integer SaleListId) {
        this.saleService.updateState(SaleListId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
    }

    //    http://localhost:8080/saleListGoods/count
    @PostMapping("/count")
    public List<SaleList> getCount(String sTime, String eTime, Integer goodsTypeId, String codeOrName) {
        return saleService.getSaleCount(sTime, eTime, goodsTypeId, codeOrName);
    }

    //    http://localhost:8080/saleListGoods/getSaleDataByDay
    @PostMapping("/getSaleDataByDay")
    public List<Map<String, Object>> getSaleDataByDay(String sTime, String eTime) {
        return saleService.getSaleDataByDay(sTime, eTime);
    }

    @PostMapping("/getSaleDataByMonth")
    public List<Map<String, Object>> getSaleDataByMonth(String sTime, String eTime) {
        return saleService.getSaleDataByMonth(sTime, eTime);
    }
}
